package util;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by ilioili on 2014/12/31.
 */
public class ToastUtil {
    private static Context context;

    public static void init(Context c) {
        context = c.getApplicationContext();
    }

    public static void showLongToast(Object obj) {
        showLongToast(context, obj);
    }

    public static void showLongToast(Context context, Object obj) {
        showToast(context, obj, Toast.LENGTH_LONG);
    }

    public static void showToast(Context context, Object obj, int time) {
        Toast toast = new Toast(context);
        toast.setDuration(time);
        toast.setGravity(Gravity.CENTER, 0, 0);
        TextView tv = new TextView(context);
        tv.setTextColor(Color.WHITE);
        tv.setGravity(Gravity.CENTER);
        tv.setBackgroundColor(Color.argb(200, 0, 0, 0));
        tv.setPadding(20, 10, 20, 10);
        tv.setText(null == obj ? "Unknow Error" : obj.toString());
        toast.setView(tv);
        toast.show();
    }

    public static void showShortToast(Object obj) {
        showShortToast(context, obj);
    }

    public static void showShortToast(Context context, Object obj) {
        showToast(context, obj, Toast.LENGTH_SHORT);
    }
}
